Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
p5.js parent() | Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild')

I do exactly as the library docs here.

I have an error

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild')

index.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="styles/index.css" />
        <script src="libs/p5.min.js"></script>
        <script src="scripts/barcode.js"></script>
    </head>
    <body>
        <div class="container"></div>
    </body>
</html>

Tried defer on the barcode script import, and putting it in the end.

barcode.js

function setup() {
    let cnv = createCanvas(500, 500);
    cnv.parent("container");
}

Tried this, nothing changed

async function setup() {
        let cnv = await createCanvas(500, 500);
        cnv.parent("container");
}

Thanks for your insight !

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As the p5 documentation says:

The parent() function is used to attach the element as a parent element.

This function accepts either a string ID, DOM node, or p5.Element Add

So add an id to container div and pass it to parent instead of class fix the problem

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="styles/index.css" />
        <script src="libs/p5.min.js"></script>
        <script src="scripts/barcode.js"></script>
    </head>
    <body>
        <div id="container"></div>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda